#include<bits/stdc++.h>
#define LL long long
#define F(x,s,t) for(int x=s;x<=t;x++)
using namespace std;
int read(){
	int x=0,f=1;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	return x*f;
}
const int N = 2e5 + 10;
int n;
int a[N];
bool b[N];
int work(){
	int cnt = 0;
	F(i, 1, n){
		for(int j = i - 1; j >= 1; j -- ){
			if(b[j] == b[i]){
				if(a[i] == a[j])cnt += a[i];
				break;
			}
		}
	}
	return cnt;
}
int main(){
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	int T = read();
	while(T -- ){
		n = read();
		F(i, 1, n)a[i] = read();
		
		int ans = 0;
		F(i, 0, (1 << n) - 1){
			F(j, 1, n)b[j] = i & (1 << (j - 1));
			ans = max(ans, work());
		}
		printf("%d\n", ans);
	}
	return 0;
}
/*
3
3
1 2 1
4
1 2 3 4
8
3 5 2 5 1 2 1 4

*/
